home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / common / ui / NetGraphGui.gui < prev    next >
Text File  |  2005-11-23  |  5KB  |  183 lines

  1. // Profiles
  2. new GuiControlProfile (NetGraphGhostsActiveProfile)
  3. {
  4.    fontColor = "255 255 255";
  5. };
  6. new GuiControlProfile (NetGraphGhostUpdatesProfile)
  7. {
  8.    fontColor = "255 0 0";
  9. };
  10. new GuiControlProfile (NetGraphBitsSentProfile)
  11. {
  12.    fontColor = "0 255 0";
  13. };
  14. new GuiControlProfile (NetGraphBitsReceivedProfile)
  15. {
  16.    fontColor = "0 0 255";
  17. };
  18. new GuiControlProfile (NetGraphLatencyProfile)
  19. {
  20.    fontColor = "0 255 255";
  21. };
  22. new GuiControlProfile (NetGraphPacketLossProfile)
  23. {
  24.    fontColor = "0 0 0";
  25. };
  26.  
  27. //--- OBJECT WRITE BEGIN ---
  28. new GuiControl(NetGraphGui) {
  29.    profile = "GuiDefaultProfile";
  30.    horizSizing = "left";
  31.    vertSizing = "bottom";
  32.    position = "0 0";
  33.    extent = "640 480";
  34.    minExtent = "8 2";
  35.    visible = "1";
  36.    noCursor = "1";
  37.    
  38.    new GuiGraphCtrl(NetGraph) {
  39.       profile = "GuiDefaultProfile";
  40.       horizSizing = "left";
  41.       vertSizing = "bottom";
  42.       position = "432 5";
  43.       extent = "200 200";
  44.       minExtent = "8 2";
  45.       visible = "1";
  46.     };
  47.  
  48.    new GuiTextCtrl(Latency) {
  49.       profile = "NetGraphLatencyProfile";
  50.       horizSizing = "left";
  51.       vertSizing = "bottom";
  52.       position = "436 184";
  53.       extent = "100 18";
  54.       minExtent = "8 2";
  55.       visible = "1";
  56.       text = "Latency";
  57.       maxLength = "255";
  58.    };
  59.    new GuiTextCtrl(PacketLoss) {
  60.       profile = "GuiTextProfile";
  61.       horizSizing = "left";
  62.       vertSizing = "bottom";
  63.       position = "536 184";
  64.       extent = "59 18";
  65.       minExtent = "8 2";
  66.       visible = "1";
  67.       text = "Packet Loss";
  68.       maxLength = "255";
  69.    };
  70.    new GuiTextCtrl(BitsReceived) {
  71.       profile = "NetGraphBitsReceivedProfile";
  72.       horizSizing = "left";
  73.       vertSizing = "bottom";
  74.       position = "536 170";
  75.       extent = "100 18";
  76.       minExtent = "8 2";
  77.       visible = "1";
  78.       text = "Bits Received";
  79.       maxLength = "255";
  80.    };
  81.    new GuiTextCtrl(GhostsActive) {
  82.       profile = "NetGraphGhostsActiveProfile";
  83.       horizSizing = "left";
  84.       vertSizing = "bottom";
  85.       position = "436 156";
  86.       extent = "100 18";
  87.       minExtent = "8 2";
  88.       visible = "1";
  89.       text = "Ghosts Active";
  90.       maxLength = "255";
  91.    };
  92.    new GuiTextCtrl(GhostUpdates) {
  93.       profile = "NetGraphGhostUpdatesProfile";
  94.       horizSizing = "left";
  95.       vertSizing = "bottom";
  96.       position = "536 156";
  97.       extent = "100 18";
  98.       minExtent = "8 2";
  99.       visible = "1";
  100.       text = "Ghost Updates";
  101.       maxLength = "255";
  102.    };
  103.    new GuiTextCtrl(BitsSent) {
  104.       profile = "NetGraphBitsSentProfile";
  105.       horizSizing = "left";
  106.       vertSizing = "bottom";
  107.       position = "436 170";
  108.       extent = "100 18";
  109.       minExtent = "8 2";
  110.       visible = "1";
  111.       text = "Bits Sent";
  112.       maxLength = "255";
  113.    };
  114. };
  115. //--- OBJECT WRITE END ---
  116.  
  117. // Functions
  118. function NetGraph::toggleNetGraph()
  119. {
  120.     if(!$NetGraph::isInitialized)
  121.     {
  122.         $Stats::netGhostUpdates = 0;
  123.         NetGraph::updateStats();
  124.         $NetGraph::isInitialized = true;
  125.     }
  126.  
  127.     if(!Canvas.isMember(NetGraphGui))
  128.     {
  129.         Canvas.add(NetGraphGui);
  130.     }
  131.     else
  132.       Canvas.remove(NetGraphGui);
  133. }
  134.  
  135. function NetGraph::updateStats()
  136. {
  137.   $NetGraphThread = NetGraph.schedule(32, "updateStats");
  138.  
  139.   if(!$Stats::netGhostUpdates)
  140.      return;
  141.  
  142.   if(isobject(NetGraph))
  143.   {
  144.     if(isobject(ServerConnection))
  145.         NetGraph.addDatum(0,ServerConnection.getGhostsActive());
  146.     GhostsActive.setText("Ghosts Active: " @ ServerConnection.getGhostsActive());
  147.     NetGraph.addDatum(1,$Stats::netGhostUpdates);
  148.     GhostUpdates.setText("Ghost Updates: " @ $Stats::netGhostUpdates);
  149.     $Stats::netGhostUpdates = 0;
  150.     NetGraph.addDatum(2,$Stats::netBitsSent);
  151.     BitsSent.setText("Bits Sent: " @ $Stats::netBitsSent);
  152.     NetGraph.addDatum(3,$Stats::netBitsReceived);
  153.     BitsReceived.setText("Bits Received: " @ $Stats::netBitsReceived);
  154.     NetGraph.matchScale(2,3);
  155.     NetGraph.addDatum(4,ServerConnection.getPing());
  156.     Latency.setText("Latency: " @ ServerConnection.getPing());
  157.     NetGraph.addDatum(5,ServerConnection.getPacketLoss());
  158.     PacketLoss.setText("Packet Loss: " @ ServerConnection.getPacketLoss());
  159.   }
  160. }
  161.  
  162. function NetGraph::toggleKey()
  163. {
  164.   if(!GhostsActive.visible)
  165.   {
  166.     GhostsActive.visible = 1;
  167.     GhostUpdates.visible = 1;
  168.     BitsSent.visible = 1;
  169.     BitsReceived.visible = 1;
  170.     Latency.visible = 1;
  171.     PacketLoss.visible = 1;
  172.   }
  173.   else
  174.   {
  175.     GhostsActive.visible = 0;
  176.     GhostUpdates.visible = 0;
  177.     BitsSent.visible = 0;
  178.     BitsReceived.visible = 0;
  179.     Latency.visible = 0;
  180.     PacketLoss.visible = 0;
  181.   }
  182. }
  183.